package com.falcon.service.impl;

import java.util.List;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import cn.hutool.core.bean.BeanUtil;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.swan.mybatis.condition.Condition;
import com.falcon.mvc.domain.BasePager;
import com.falcon.core.utils.BeanUtils;

import com.falcon.domain.po.QuestionnaireAnswerSheetPO;
import com.falcon.domain.dos.QuestionnaireAnswerSheetDO;
import com.falcon.domain.req.QuestionnaireAnswerSheetQuery;
import com.falcon.domain.req.QuestionnaireAnswerSheetRequest;

import com.falcon.mapper.IQuestionnaireAnswerSheetMapper;
import com.falcon.service.IQuestionnaireAnswerSheetService;


@Slf4j
@Service
public class QuestionnaireAnswerSheetService implements IQuestionnaireAnswerSheetService {

    @Autowired
    private IQuestionnaireAnswerSheetMapper questionnaireAnswerSheetMapper;

    @Override
    public Long save(QuestionnaireAnswerSheetRequest request){
        QuestionnaireAnswerSheetPO questionnaireAnswerSheetPO = BeanUtil.copyProperties(request, QuestionnaireAnswerSheetPO.class);

        this.questionnaireAnswerSheetMapper.insertNotNull(questionnaireAnswerSheetPO);

        return questionnaireAnswerSheetPO.getId();
    }

    @Override
    public Boolean update(Long id, QuestionnaireAnswerSheetRequest request){

        QuestionnaireAnswerSheetPO questionnaireAnswerSheetPO = BeanUtil.copyProperties(request, QuestionnaireAnswerSheetPO.class);
        questionnaireAnswerSheetPO.setId(id);

        return this.questionnaireAnswerSheetMapper.updateNotNull(questionnaireAnswerSheetPO);
    }

    @Override
    public Boolean deleteById(Long id) {

        return this.questionnaireAnswerSheetMapper.deleteById(id);
    }

    @Override
    public QuestionnaireAnswerSheetDO queryById(Long id){

        QuestionnaireAnswerSheetPO questionnaireAnswerSheetPO = this.questionnaireAnswerSheetMapper.selectById(id);

        QuestionnaireAnswerSheetDO questionnaireAnswerSheetDO = BeanUtil.copyProperties(questionnaireAnswerSheetPO, QuestionnaireAnswerSheetDO.class);

        return questionnaireAnswerSheetDO;
    }


    @Override
    public List<QuestionnaireAnswerSheetDO> queryList(QuestionnaireAnswerSheetQuery request){

        Condition condition = request.toCondition();

        List<QuestionnaireAnswerSheetPO> poList = this.questionnaireAnswerSheetMapper.selectList(condition);

        List<QuestionnaireAnswerSheetDO> doList = BeanUtil.copyToList(poList, QuestionnaireAnswerSheetDO.class);

        return doList;
    }

    @Override
    public BasePager<QuestionnaireAnswerSheetDO> queryPager(QuestionnaireAnswerSheetQuery request){


        PageInfo<QuestionnaireAnswerSheetPO> pageInfo = PageHelper.startPage(request.getPage(), request.getPageSize())
                .doSelectPageInfo(() -> this.questionnaireAnswerSheetMapper.selectList(request.toCondition()));

        return BeanUtils.toPager(pageInfo, QuestionnaireAnswerSheetDO.class);
    }

    @Override
    public int batchDelete(List<Long> ids) {

        return this.questionnaireAnswerSheetMapper.deleteByIds(ids);
    }


}

